package com.mustafaiev.tair.cts.tapestry.encoder;

import org.apache.tapestry5.ValueEncoder;

import com.mustafaiev.tair.cts.facade.IPayerFacade;
import com.mustafaiev.tair.cts.tapestry.dto.PayerDTO;

public class PayerSelectEncoder implements ValueEncoder<PayerDTO> {

    private final IPayerFacade facade;

    public PayerSelectEncoder(final IPayerFacade facade) {
        this.facade = facade;
    }

    public String toClient(final PayerDTO value) {
        return String.valueOf(value.getId());
    }

    public PayerDTO toValue(final String clientValue) {
        PayerDTO dto = new PayerDTO();
        if (clientValue != null) {
            dto = facade.retrievePayer(Long.valueOf(clientValue));
        }
        return dto;
    }

}
